const wda = document.getElementById("wd-a");
const wdit = document.querySelectorAll(".wd-it");

wda.onclick = function () {
    if (wda.checked === false) {
        for (let i = 0; i < wdit.length; i++) {
            wdit[i].checked = false;
        }
        $("#agree").prop("disabled", true);
        $("#refuse").prop("disabled", true);
    } else {
        for (let i = 0; i < wdit.length; i++) {
            wdit[i].checked = true;
        }
        $("#agree").prop("disabled", false);
        $("#refuse").prop("disabled", false);
    }
}

for (let i = 0; i < wdit.length; i++){
    wdit[i].addEventListener("click",function (){
        let a=0;
        if(wdit[i].checked===true){
            $("#agree").prop("disabled", false);
            $("#refuse").prop("disabled", false);
            a=1;
        }else {
            for(let j=0;j<wdit.length;j++){
                if (wdit[j].checked === true){
                    $("#agree").prop("disabled", false);
                    $("#refuse").prop("disabled", false);
                    a=1;
                }
            }
        }
        if(a===0){
            $("#agree").prop("disabled", true);
            $("#refuse").prop("disabled", true);
        }
    })
}

const  fid=document.getElementsByClassName("f_id");
const ftel = document.getElementsByClassName("f_tel");
const fmn=document.getElementsByClassName("f_mn");
const wd_it = document.getElementsByClassName("wd-it");
let ids=[];
let tels = [];
let mns=[];
let sh=0;
function SH(btn) {
    for (let i = 0; i < fid.length; i++) {
        if (wd_it[i].checked === true) {
            ids.push(fid[i].innerHTML);
            tels.push(ftel[i].innerHTML);
            mns.push(fmn[i].innerHTML);
        }
    }

    // 检查idList是否为空
    if(!tels || tels.length === 0 ||!mns || mns.length===0||!ids||ids.length===0) {
        alert('请至少选择一条申请!');
        $("#tc").css('display',"none");
        return;
    }else if(tels.length!==mns.length||tels.length!==ids.length||mns.length!==ids.length){
        alert("网页异常,请刷新后重试!");
        return;
    }

    if(btn.textContent==="拒绝选中"){
        sh=-1;
    }else if(btn.textContent==="同意选中"){
        sh=1;
    }else {
        return;
    }
    //ajax 删除请求
    $.ajax({
        url: "/admins/A_SH_Recharge",
        type: 'post',
        data: {
            idList: ids.join(','),
            telList: tels.join(','),
            mnList: mns.join(','),
            sh: sh
        },
        success: function (Result){
            tels=[];
            alert(Result.msg);
            window.location.href="/admins/A_DS_Recharge";
        },
        error: function () {
            alert("请求失败!");
        }
    })
}

$("#c").click(function (){
    if($("#cin").val()!==""){
        // 发送Ajax请求;
        $.ajax({
            url: "/admins/A_DS_Recharge",
            type: "get",
            data:{
                keywords:$("#cin").val()
            },
            success: function (result) {
                $('#data').html($(result).find('#data').html());
                $('div.pages').html($(result).find('div.pages').html());
            },
            error: function () {
                alert("查询失败,请稍后重试!");
            }
        });
    }else {
        $("#cin").addClass("input change");
        $("#cin").attr("placeholder","查询条件不能为空!");
    }
});